package com.yanyeori.framework.datasource.builder;

import com.yanyeori.framework.datasource.configprop.DataSourceConfigProps;
import com.yanyeori.framework.datasource.configprop.MultiDataSourceConfigProps;

import javax.sql.DataSource;

/**
 * Default DataSource Builder：只配置url、用户密码等基础信息
 *
 * @author chenkuan 2021/4/16
 */
public class DefaultDataSourceBuilder implements DataSourceBuilder {

    @Override
    public DataSource build(DataSourceConfigProps props, MultiDataSourceConfigProps basicProps) {
        org.springframework.boot.jdbc.DataSourceBuilder<?> builder = org.springframework.boot.jdbc.DataSourceBuilder.create();
        return builder.type(props.getType())
                .url(basicProps.getUrl())
                .username(basicProps.getUsername())
                .password(basicProps.getPassword())
                .driverClassName(basicProps.getDriverClassName())
                .build();
    }

    @Override
    public Class<? extends DataSource> getType() {
        return null;
    }
}
